<template>
  <div class="common-btn" :class="{ disabled: disabled }" @click="click">
    <div class="inner">
      <div><slot name="icon"></slot></div>
      <span><slot></slot></span>
    </div>
  </div>
</template>
<script>
export default {
  name: 'CommonBtn',
  props: {
    disabled: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    click() {
      if (!this.disabled) {
        this.$emit('click');
      }
    }
  }
};
</script>
<style lang="scss">
.common-btn {
  background-color: #02bcec;
  border-radius: 3px;
  height: 30px;
  cursor: pointer;
  text-align: center;
  font-size: 16px;
  padding: 1px;
  box-sizing: border-box;
  position: relative;
  color: #fff;
  &.disabled {
    cursor: not-allowed;
    background: transparent;
    .inner {
      background: #004a61;
      border-color: #01394b;
    }
    color: #7ab8cb;
  }
  :not(.disabled) {
    &:hover {
      &::before {
        opacity: 0.25; /* 鼠标移上去时遮罩显示的透明度 */
      }
    }
  }
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    opacity: 0;
    transition: opacity 0.3s; /* 添加过渡效果 */
    z-index: 1;
    border-radius: 3px;
  }

  .inner {
    text-align: center;
    font-size: 16px;
    display: inline-block;
    background-color: #02bcec;
    border: 2px solid #00637d;
    border-radius: 3px;
    opacity: 1;
    width: 100%;
    height: 100%;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
